<template>
  <view class="content">
    <view class="tabs">
      <view @tap="tab('1')" :class="showType == 1 ? 'tab act' : 'tab' ">
        <text>每日反馈 </text>
      </view>
      <view @tap="tab('2')" :class="showType == 2 ? 'tab act' : 'tab' ">
        <text>每月反馈</text>
      </view>
      <view @tap="tab('3')" :class="showType == 3 ? 'tab act' : 'tab' ">
        <text>学习进度</text>
      </view>
    </view>
    <view class="searchBox">
      <u-calendar :show="show" mode="range" @confirm="confirm" @close="show = false" :allowSameDay="true"
        :minDate="minDate" :closeOnClickOverlay="true" monthNum="13"></u-calendar>
      <view class="timeBox" @click="show = true">
        <span style="margin-right: 10rpx;">日期</span>
        <view class="time">
          <image src="../../static/img/time.png" mode=""></image>
          {{info.start_date}}
        </view>
        <view style="margin: 0 10rpx;">
          至
        </view>
        <view class="time">
          <image src="../../static/img/time.png" mode=""></image>
          {{info.end_date}}
        </view>
      </view>
      <view class="iptBox">
        <input class="ipt" type="text" placeholder="输入关键词" placeholder-class="iptPla" v-model="info.search_data">
        <view class="searchBtn" @tap="getFeedbackMonthList()">
          搜索
        </view>
      </view>
    </view>

    <view class="list">
      <view class="item flex f-21  c-66" v-for="(i,k) in list" :key="k" @tap="goMonthDetail(i.id)">
        <view class="itemLeft">
          <view class="header flex">
            <view class="time" style="width: 40%;">
              {{i.month}}
            </view>
            <view class="duration" style="width: 60%;">
              <image src="../../static/img/account.png" mode=""></image>
              {{i.user.username}}<text v-if="i.user.grade">({{i.user.grade}})</text>
            </view>
            <view class="bomBtn" v-if="i.examine_state == 0" @tap.stop="examineFeedbackDay(i)">
              审核
            </view>
          </view>

          <view class="flex" style="margin: 10rpx 0;">
            <view class="" style="width: 40%;">
              状态：
              <text class="redText" v-if="i.state == 0">未通过</text>
              <text class="redText" v-if="i.state == 1">通过</text>
            </view>
            <view class="" style="width: 60%;margin-left: auto;">
              审核时间：<text style="color: #00BAAD;">{{i.examine_time}}</text>
            </view>
          </view>
        </view>
        <view class="itemRight">
          <image src="../../static/img/open.png" mode=""></image>
        </view>
      </view>
    </view>
    <!-- 审核模态框 -->
    <u-modal :show="examineShow" showCancelButton @cancel="examineShow = false" @confirm="examineConfirm">
      <view class="modalForm">
        <view class="item flex">
          <view class="lable">
            学生:
          </view>
          <view class="">
            {{user.username}}
            <text style="color: #666;">{{users.day}}({{users.start_time}}-{{users.end_time}})</text>
          </view>
        </view>
        <view class="item flex">
          <view class="lable">
            审核
          </view>
          <view class="stateBox" @tap="pickerShow = true">
            {{stateText}}
            <u-icon class="icon" name="arrow-down" size="22rpx"></u-icon>
          </view>
        </view>
        <view class="item">
          <u--textarea v-model="examineInfo.examine_note" placeholder="原因"></u--textarea>
        </view>
      </view>
    </u-modal>
    <u-picker :show="pickerShow" :columns="columns" keyName="label" @cancel="pickerShow = false"
      @confirm="confirmState"></u-picker>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        show: false,
        examineShow: false,
        pickerShow: false,
        info: {
          start_date: '',
          end_date: '',
          search_data: '',
          page: 1,
          size: 10
        },
        minDate: '',
        list: [],
        showType: 2,
        columns: [
          [{
            label: '通过',
            // 其他属性值
            id: 1
            // ...
          }, {
            label: '拒绝',
            id: 2
          }]
        ],
        stateText: '选择状态',
        examineInfo: {
          id: '',
          examine_state: '',
          examine_note: ''
        },
        users: {

        },
        user: {}
      }
    },
    onLoad() {
      this.chooseTimed()
      this.getDate()
      this.getFeedbackMonthList()
    },
    methods: {
      tab(n) {
        this.showType = n
        if (n == 1) {
          uni.navigateTo({
            url: './day'
          })
        }
        if (n == 3) {
          uni.navigateTo({
            url: './study'
          })
        }
      },
      // 设置默认日期，最大值为今天，最小值为去年今天
      chooseTimed() {
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        if (month <= 9) {
          month = '0' + month;
        }
        if (day <= 9) {
          day = '0' + day;
        }
        let minyear = year - 1;
        this.minDate = minyear + '-' + month + '-' + day;
        this.maxDate = year + '-' + month + '-' + day;
      },
      getDate() {
        const currentDate = new Date();
        const year = currentDate.getFullYear();
        const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份是从0开始的
        const day = currentDate.getDate().toString().padStart(2, '0');
        const formattedDate = `${year}-${month}-${day}`;
        this.info.start_date = formattedDate
        this.info.end_date = formattedDate
      },
      confirm(e) {
        this.info.start_date = e[0].replace(/-/g, "-");
        this.info.end_date = e[e.length - 1].replace(/-/g, "-");
        this.show = false
      },
      async getFeedbackMonthList() {
        uni.stopPullDownRefresh();
        const {
          data: res
        } = await uni.$http.post('school/feedback/getFeedbackMonthList', this.info)
        if (res.code != 1) {
          return this.toast.msg(res.msg)
        }
        if (res.data.data.length) {
          this.list = this.list.concat(res.data.data);
          this.info.page += 1;
        } else {
          this.hasMore = false;
          this.toast.msg('没有更多数据了！')
        }
      },
      goMonthDetail(id) {
        uni.navigateTo({
          url: `/pages/feedback/monthDetail?id=${id}`
        })
      },
      confirmState(e) {
        this.stateText = e.value[0].label
        this.examineInfo.examine_state = e.value[0].id
        this.pickerShow = false
      },
      async examineConfirm() {
        console.log(this.examineInfo);
        const {
          data: res
        } = await uni.$http.post('school/feedback/examineFeedbackMonth', this.examineInfo)
        if (res.code != 1) {
          this.toast.msg(res.msg)
          return
        }
        this.examineShow = false
        this.toast.msg('审核成功！')
      }
    },
    onReachBottom() {
      this.getFeedbackMonthList()
    },
    onPullDownRefresh() {
      this.info.page = 1,
        this.info.size = 10,
        this.info.search_data = '',
        this.list = []
      this.getFeedbackMonthList()
    },
  }
</script>

<style lang="scss">
  .content {
    min-height: 100vh;

    .tabs {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 10rpx;

      .tab {
        width: 184rpx;
        height: 65rpx;
        text-align: center;
        line-height: 65rpx;
        font-size: 28rpx;
        color: #666;
        border-radius: 8rpx;
        background: linear-gradient(90deg, #E5E5E5 0%, #E8E8E8 100%);
        margin-right: 10rpx;
        font-weight: 700
      }

      .act {
        background: linear-gradient(90deg, #AC33C1 0%, #7948EA 100%);
        color: #fff;
      }
    }

    .star {
      color: #D43030;
      margin-left: 11rpx;
    }

    .btns {
      color: #FFFFFF;
      text-align: center;
      line-height: 36rpx;
      font-size: 21rpx;
      margin-left: 293rpx;
      display: flex;

      view {
        width: 80rpx;
        height: 36rpx;
        border-radius: 8rpx;
      }

      .cancel {
        background: #A6A6A6;
        margin-right: 32rpx;
      }

      .confirm {
        background-color: #2A82E4;
      }
    }

    .searchBox {
      width: 670rpx;
      margin: 0 auto;
      padding: 0 20rpx;

      .timeBox {
        display: flex;
        height: 78rpx;
        line-height: 78rpx;
        align-items: center;
        margin-bottom: 18rpx;
        font-size: 21rpx;

        .time {
          width: 250rpx;
          height: 78rpx;
          border-radius: 10rpx;
          background: #FFFFFF;
          border: 2rpx solid #FCF7F7;
          padding-left: 26rpx;
          color: #666;

          image {
            width: 35rpx;
            height: 35rpx;
            margin-right: 17rpx;
            vertical-align: middle;
          }
        }
      }

      .iptBox {
        display: flex;

        .ipt {
          box-sizing: border-box;
          width: 378rpx;
          height: 66rpx;
          padding-left: 75rpx;
          border: 2rpx solid #FCF7F7;
          border-radius: 10rpx;
          margin-right: auto;
        }

        .iptPla {
          color: #999;
          font-size: 22rpx;
        }

        .searchBtn {
          display: inline-block;
          background: #A6A6A6;
          width: 100rpx;
          height: 66rpx;
          line-height: 66rpx;
          text-align: center;
          border-radius: 10rpx;
          margin-left: 20rpx;
          font-size: 24rpx;
        }

        .addBtn {
          width: 100rpx;
          height: 66rpx;
          line-height: 66rpx;
          text-align: center;
          border-radius: 10rpx;
          font-size: 24rpx;
          background: linear-gradient(90deg, #7948EA 0%, #1AADA4 100%);
          color: #fff;
          margin-left: 14rpx;
        }
      }
    }

    .list {
      width: 698rpx;
      margin: 0 auto;
      margin-top: 20rpx;

      .item {
        margin-bottom: 15rpx;
        width: 698rpx;
        height: 105rpx;
        border-radius: 10rpx;
        background: #FFFFFF;
        border: 2rpx solid #ECECEC;
        color: #999;
        font-size: 24rpx;
        padding: 20rpx 0 20rpx 20rpx;

        .itemLeft {
          width: 600rpx;

          .time {
            color: #333;
            font-weight: 700;
          }

          .redText {
            color: #E33C64;
          }

          .header {
            .duration {
              margin-left: auto;
              padding-right: 100rpx;

              image {
                width: 25rpx;
                height: 27rpx;
                margin-right: 5rpx;
              }
            }

            .bomBtn {
              margin-left: auto;
              width: 82rpx;
              height: 31rpx;
              border-radius: 5rpx;
              text-align: center;
              line-height: 31rpx;
              font-size: 17rpx;
              color: #fff;
              background: linear-gradient(90deg, #7948EA 0%, #AC33C1 100%);
            }
          }

        }

        .itemRight {
          margin-left: auto;
          margin-right: 30rpx;
          width: 20rpx;
          transform: rotate(-90deg);

          image {
            width: 18rpx;
            height: 20rpx;
          }
        }
      }
    }
  }
</style>